package com.px.project.module.ml.service.impl;

import java.util.List;

import com.px.project.module.ml.dto.MechanicalEquipmentInfoDto;
import com.px.project.module.ml.entity.MechanicalEquipmentInfoDao;
import com.px.project.module.ml.mapper.IMechanicalEquipmentInfoMapper;
import com.px.project.module.ml.service.IMechanicalEquipmentInfoService;
import com.px.project.module.ml.vo.MechanicalEquipmentInfoVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;

/**
 * 物资系统》》机械设备业务逻辑实现
 *
 * @author 品讯科技
 * @date 2024-08
 */
@Service
@RequiredArgsConstructor
public class MechanicalEquipmentInfoServiceImpl extends ServiceImpl<IMechanicalEquipmentInfoMapper, MechanicalEquipmentInfoDao>
    implements IMechanicalEquipmentInfoService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveOne(MechanicalEquipmentInfoDto mechanicalEquipmentInfo) {
        MechanicalEquipmentInfoDao mechanicalEquipmentInfoDao = BeanUtil.copyProperties(mechanicalEquipmentInfo, MechanicalEquipmentInfoDao.class);
        return super.save(mechanicalEquipmentInfoDao);
    }

    @Override
    public List<MechanicalEquipmentInfoVo> listOfAll() {
        QueryWrapper<MechanicalEquipmentInfoDao> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().orderByDesc(MechanicalEquipmentInfoDao::getCreateTime);
        List<MechanicalEquipmentInfoDao> mechanicalEquipmentInfos = super.list(queryWrapper);
        return BeanUtil.copyToList(mechanicalEquipmentInfos, MechanicalEquipmentInfoVo.class);
    }
}